package com.alogic.matcher.impl;

import com.alogic.matcher.CommonMatcher;
import com.anysoft.util.Properties;
import com.anysoft.util.TimeBucketGroup;

/**
 * 时间段匹配器
 *
 * @since 1.6.13.7 [20200720 duanyy] <br>
 */
public class TimeBucketMatcher implements CommonMatcher {

    protected TimeBucketGroup group = null;

    public TimeBucketMatcher(String regex, Properties p){
        group = new TimeBucketGroup(regex);
    }

    @Override
    public boolean isMatch(String data) {
        return group != null?group.match(getLong(data,System.currentTimeMillis())):false;
    }

    private long getLong(String v,long dft){
        try{
            return Long.parseLong(v);
        }catch (NumberFormatException ex){
            return dft;
        }
    }
}
